<?php
/*
 * 公司动态
 */
namespace app\index\controller;

use app\common\controller\IndexBase;
use think\facade\Session;
use think\facade\Db;

class News extends IndexBase
{
    protected function initialize()
    {
        parent::initialize();
    }

    public function index()
    {
        $page = $this->request->param('page');
        if (empty($page))
        {
            $page = 0;
        }
        $data = Db::table('article')->where(['status'=>1])->order('create_time','DESC')->limit($page,10)->select()->toArray();
        foreach ($data as $key => $v) {
            $data[$key]['id'] = $this->hashids->encode($v['id']);
        }
    	return $this->fetch('',['page_title'=>'公司动态','data'=>$data]);
    }
    //新闻详情
    public function detail()
    {
        $code = $this->request->param('code');
        $id = $this->hashids->decode($code);
        $data = Db::table('article')->where(['status'=>1])->find($id);
        return $this->fetch('',['page_title'=>$data['name'],'data'=>$data]);
    }

}